
#include "session.h"
#include "util.h"
#include <windows.h>
#include <wtsapi32.h>
#include <thread>

extern PROCESS_INFORMATION processInfo;
extern DWORD dwSessionId;

// int main(){

//     checkWindowSession();

// }
void checkWindowSession()
{

    while (TRUE)
    {
        Sleep(2000);
        BEGIN_EXCEPT
        DWORD currentSessionId = WTSGetActiveConsoleSessionId();
        if (currentSessionId == 0)
        {
            continue;
        }
        if (dwSessionId != currentSessionId && dwSessionId != 0 && processInfo.hProcess!=0)
        {
            TerminateProcess(processInfo.hProcess, 0);
            processInfo={0};
            dwSessionId=0;
        }
        END_EXCEPT
        // DHS_LOG("checkWindowSession %d", std::this_thread::get_id());
    }
}